package com.quyunshuo.module.home.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.quyunshuo.module.home.room.entity.PoetEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface PoetDao {
    // 插入单个诗人
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(poet: PoetEntity)

    // 插入多个诗人
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(poets: List<PoetEntity>)

    @Query("SELECT *, id FROM poets")
    suspend fun getAll():List<PoetEntity>

    // 获取所有诗人
    @Query("SELECT * FROM poets")
    fun getAllPoets(): Flow<List<PoetEntity>>

    // 按ID获取诗人
    @Query("SELECT * FROM poets WHERE id = :id")
    fun getPoetById(id: Long): Flow<PoetEntity>

    // 随机获取几位诗人
    @Query("SELECT * FROM poets ORDER BY RANDOM() LIMIT :count")
    fun getRandomPoets(count: Int): Flow<List<PoetEntity>>

    // 删除所有诗人
    @Query("DELETE FROM poets")
    suspend fun deleteAll()
}